Skip to content

feat: custom priority validator#3

Draft
basgys wants to merge 1 commit intomainfrom
feat/custom-priority-validator
Draft

feat: custom priority validator#3
basgys wants to merge 1 commit intomainfrom
feat/custom-priority-validator

Conversation

@basgys
Copy link
Contributor

@basgys basgys commented Dec 19, 2024

Work in progress to show how Bulwark could be configured to handle invalid priority values. All the options provide a different way to alert the developer that the library is misused.

The default behaviour went from panicking to a quiet adjustment with a warning log.

return p, err
}

// This is a safeguard in case the validator function does not return a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is more informative BUT it halts the entity application regular execution flow. As I see, it is up to the caller to inform "loudly" on errors which are consider critical for the regular execution of its business logic. Making a decision within a library which lacks on the context of its usage, can become highly disturbing for its usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Instead of returning a panic, I will return an error. It seems like changing the default behaviour from a panic to returning an error is the best option to let the caller know that the priority is incorrect in a more graceful way.

// of `[0, priorities)` will panic.
func NewAdaptiveThrottle(priorities int, options ...AdaptiveThrottleOption) *AdaptiveThrottle {
if priorities <= 0 {
panic("bulwark: priorities must be greater than 0")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No a big fan of panics. I understand the goal is to make this change backward compatible but my concern isin certain cases where NewAdaptiveThrottle() is called depending on application states (no the case atm anywhere though) it might lead to unexpected service disruptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants